#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>

int main(void)
{
    int buttons_fd;
    char buttons[6] = {0, 0, 0, 0, 0, 0};

    buttons_fd = open("/dev/key_init", 0);
    if (buttons_fd < 0) {
        perror("open device key_init");
        exit(1);
    }

    for (;;) {
        int i;

        if (read(buttons_fd, buttons, sizeof buttons) != sizeof buttons) {
            perror("read buttons:");
            exit(1);
        }

        for (i = 0; i < sizeof buttons / sizeof buttons[0]; i++) {
            if (buttons[i])
                printf("key [%d] had pressed\n", i+1);
        }
    }

    close(buttons_fd);

    return 0;
}

// https://bigban.iteye.com/blog/2257552
